import requests
import os


url = "https://api.birdreport.cn/front/activity/search"

import subprocess
from functools import partial

subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs

# 获取当前脚本所在目录
script_dir = os.path.dirname(os.path.abspath(__file__))
js_file_path = os.path.join(script_dir, "19.js")

with open(js_file_path, "r", encoding="utf-8") as f:
    js_code = f.read()
# 编译 JS 代码
ctx = execjs.compile(js_code)
params = ctx.call("getDatas",'{"limit":"20","page":"1"}')
timestamp = str(params['timestamp'])
headers = {
    "Accept": "application/json, text/javascript, */*; q=0.01",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "Connection": "keep-alive",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Origin": "https://www.birdreport.cn",
    "Referer": "https://www.birdreport.cn/",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-site",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0",
    "requestId": params['requestId'],
    "sec-ch-ua": "\"Chromium\";v=\"142\", \"Microsoft Edge\";v=\"142\", \"Not_A Brand\";v=\"99\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sign": params['sign'],
    "timestamp": timestamp
}
response = requests.post(url, headers=headers, data=params['data'])
print(response.json()['data'])
res = ctx.call('getDecodeData', response.json()['data'])
print(res)
